var a = require("../../../@babel/runtime/helpers/toConsumableArray"), t = require("../../../@babel/runtime/helpers/createForOfIteratorHelper");

require("../../../@babel/runtime/helpers/Arrayincludes");

var e = getApp();

function i(a) {
    switch (a) {
      case 1:
        return "未结算";

      case 2:
        return "已结算";

      case 3:
        return "失效";
    }
}

Page({
    data: {
        currentShowType: 1,
        awardData: [],
        loading: !1,
        isMoreData: !0,
        page: 1,
        agent: null
    },
    onLoad: function() {
        this.getAgent(), wx.setNavigationBarTitle({
            title: "推广中心"
        });
    },
    onReachBottom: function() {
        !1 !== this.data.loading && !0 !== this.data.isMoreData || this.getAwardData();
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {},
    getAgent: function() {
        var a = this, t = e.getNetAddresss("plugin.agency.api.agency.index");
        e._postNetWork({
            url: t,
            success: function(t) {
                var e = t.data, i = e.data, r = e.result, n = e.msg;
                if (0 === r) return wx.hideLoading(), void wx.showToast({
                    title: n,
                    success: function(a) {
                        wx.navigateBack({
                            delta: 1
                        });
                    }
                });
                a.setData({
                    agent: i
                }), wx.hideLoading(), a.getAwardData();
            }
        });
    },
    switchTabs: function(a) {
        var t = this, e = parseInt(a.detail.name), i = !0;
        [ 1, 3, 4 ].includes(e) && (i = !1), this.setData({
            awardData: [],
            loading: !1,
            isMoreData: !0,
            page: 1,
            currentShowType: e,
            hiddenNormalList: i
        }, function() {
            t.getAwardData();
        });
    },
    getAwardData: function() {
        var r = this;
        if (!0 !== this.data.loading && !1 !== this.data.isMoreData) {
            this.setData({
                loading: !0
            }), wx.showLoading({
                title: "加载中",
                mask: !0
            });
            var n = e.getNetAddresss("plugin.agency.api.award.get-list");
            n += "&agency_type=" + this.data.currentShowType + "&page=" + this.data.page, e._postNetWork({
                url: n,
                success: function(e) {
                    var n = e.data, s = n.data, d = n.result, o = n.msg;
                    if (0 === d) return wx.hideLoading(), void wx.showToast({
                        title: o,
                        success: function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }
                    });
                    var g = {};
                    (s.current_page == s.last_page || 0 === s.data.length || s.data.length < per_page) && (g.isMoreData = !1);
                    var u, c = r.data.awardData, l = s.data, h = t(l);
                    try {
                        for (h.s(); !(u = h.n()).done; ) {
                            var p = u.value;
                            p.award_status_text = i(p.award_status);
                        }
                    } catch (a) {
                        h.e(a);
                    } finally {
                        h.f();
                    }
                    c.push.apply(c, a(l)), g.awardData = c, g.loading = !1, c.page = r.data.page + 1, 
                    r.setData(g), wx.hideLoading();
                }
            });
        }
    }
});